package top.wu2020.lazy.ws.chat.application.impl;

import org.wu.framework.database.lazy.web.plus.stereotype.LazyApplication;
import top.wu2020.lazy.ws.chat.application.HistorySessionApplication;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import top.wu2020.lazy.ws.chat.domain.model.history.session.HistorySession;
import top.wu2020.lazy.ws.chat.application.command.history.session.HistorySessionRemoveCommand;
import top.wu2020.lazy.ws.chat.application.command.history.session.HistorySessionStoryCommand;
import top.wu2020.lazy.ws.chat.application.command.history.session.HistorySessionUpdateCommand;
import top.wu2020.lazy.ws.chat.application.command.history.session.HistorySessionQueryListCommand;
import top.wu2020.lazy.ws.chat.application.command.history.session.HistorySessionQueryOneCommand;
import top.wu2020.lazy.ws.chat.application.assembler.HistorySessionDTOAssembler;
import top.wu2020.lazy.ws.chat.application.dto.HistorySessionDTO;
import java.util.stream.Collectors;
import jakarta.annotation.Resource;
import top.wu2020.lazy.ws.chat.domain.model.history.session.HistorySessionRepository;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe history_session 
 *
 * @author Jia wei Wu
 * @date 2024/05/24 08:52 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class HistorySessionApplicationImpl implements HistorySessionApplication {

    @Resource
    HistorySessionRepository historySessionRepository;
    /**
     * describe 新增
     *
     * @param historySessionStoryCommand 新增     
     * @return {@link Result<HistorySession>} 新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<HistorySession> story(HistorySessionStoryCommand historySessionStoryCommand) {
        HistorySession historySession = HistorySessionDTOAssembler.INSTANCE.toHistorySession(historySessionStoryCommand);
        return historySessionRepository.story(historySession);
    }
    /**
     * describe 批量新增
     *
     * @param historySessionStoryCommandList 批量新增     
     * @return {@link Result<List<HistorySession>>} 新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<HistorySession>> batchStory(List<HistorySessionStoryCommand> historySessionStoryCommandList) {
        List<HistorySession> historySessionList = historySessionStoryCommandList.stream().map( HistorySessionDTOAssembler.INSTANCE::toHistorySession).collect(Collectors.toList());
        return historySessionRepository.batchStory(historySessionList);
    }
    /**
     * describe 更新
     *
     * @param historySessionUpdateCommand 更新     
     * @return {@link Result<HistorySession>} 领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<HistorySession> updateOne(HistorySessionUpdateCommand historySessionUpdateCommand) {
        HistorySession historySession = HistorySessionDTOAssembler.INSTANCE.toHistorySession(historySessionUpdateCommand);
        return historySessionRepository.story(historySession);
    }

    /**
     * describe 查询单个
     *
     * @param historySessionQueryOneCommand 查询单个     
     * @return {@link Result<HistorySessionDTO>} DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<HistorySessionDTO> findOne(HistorySessionQueryOneCommand historySessionQueryOneCommand) {
        HistorySession historySession = HistorySessionDTOAssembler.INSTANCE.toHistorySession(historySessionQueryOneCommand);
        return historySessionRepository.findOne(historySession).convert(HistorySessionDTOAssembler.INSTANCE::fromHistorySession);
    }

    /**
     * describe 查询多个
     *
     * @param historySessionQueryListCommand 查询多个     
     * @return {@link Result<List<HistorySessionDTO>>} DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<HistorySessionDTO>> findList(HistorySessionQueryListCommand historySessionQueryListCommand) {
        HistorySession historySession = HistorySessionDTOAssembler.INSTANCE.toHistorySession(historySessionQueryListCommand);
        return historySessionRepository.findList(historySession)        .convert(historySessions -> historySessions.stream().map(HistorySessionDTOAssembler.INSTANCE::fromHistorySession).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个
     *
     * @param historySessionQueryListCommand 分页查询多个     
     * @return {@link Result<LazyPage<HistorySessionDTO>>} 分页DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<LazyPage<HistorySessionDTO>> findPage(int size,int current,HistorySessionQueryListCommand historySessionQueryListCommand) {
        HistorySession historySession = HistorySessionDTOAssembler.INSTANCE.toHistorySession(historySessionQueryListCommand);
        return historySessionRepository.findPage(size,current,historySession)        .convert(page -> page.convert(HistorySessionDTOAssembler.INSTANCE::fromHistorySession))            ;
    }

    /**
     * describe 删除
     *
     * @param historySessionRemoveCommand 删除     
     * @return {@link Result<HistorySession>}      
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<HistorySession> remove(HistorySessionRemoveCommand historySessionRemoveCommand) {
     HistorySession historySession = HistorySessionDTOAssembler.INSTANCE.toHistorySession(historySessionRemoveCommand);
     return historySessionRepository.remove(historySession);
    }

}